var koa = require('koa');
var render = require('koa-ejs');

var app = koa();


// renderer

render(app, {
    root: __dirname,
    layout: false,
    viewExt: 'html',
    cache: false,
    debug: true
});



// x-response-time
app.use(function* (next) {
    var start = new Date();
    yield next;
    var ms = new Date().getTime() - start.getTime();
    this.set('X-Response-Time', ms + 'ms');
});

// logger
app.use(function* (next) {
    var start = new Date();
    yield next;
    var ms = new Date().getTime() - start.getTime();
    console.log('%s %s - %s', this.method, this.url, ms);
});

// app.use(function* (next) {
//     //console.log(this.request);
//     //console.log(this.request);
//     //yield this.render('about');
//     //yield next;
//     //console.log(this.state);
// });

app.use(require('./home.js').routes());

app.use(require('./about.js').routes());

app.use(function* () {
    this.body = 'hello world';
});

app.listen(3000);